package diploma.kisel.modelas.service;

import java.util.List;

import diploma.kisel.modelas.domain.Project;
import diploma.kisel.modelas.domain.User;
import diploma.kisel.modelas.repository.ProjectRepositoryImpl;
import diploma.kisel.modelas.repository.api.ProjectRepository;
import diploma.kisel.modelas.service.api.ProjectService;

public class ProjectServiceImpl implements ProjectService{
	
	private ProjectRepository projectRepository = new ProjectRepositoryImpl();

	@Override
	public List<Project> findAll() {
		return projectRepository.findAll();
	}

	@Override
	public Project findById(int id) {
		if (id>=0) 
			return projectRepository.findById(id);
		else
			return null;
	}

	@Override
	public Project save(Project project) {
		if (project.getId()!=null) 
			return projectRepository.update(project);
		else
			return projectRepository.save(project);
	}

	@Override
	public void remove(Project project) {
		if (project.getId()!=null)
			projectRepository.remove(project);
		
	}

	@Override
	public void remove(int id) {
		Project project = projectRepository.findById(id);
		projectRepository.remove(project);		
	}

	@Override
	public List<Project> findByUser(User user) {
		return projectRepository.findByUser(user);
	}

}
